package com.example.learndevice.ui

import android.hardware.Camera
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.learndevice.R
import com.example.learndevice.adapter.CameraAdapter
import com.example.learndevice.bean.CameraInfo
import com.example.learndevice.databinding.ActivityCamaraInfoBinding
import com.example.mydefinedview1.base.BaseActivity

class CamaraInfoActivity : BaseActivity<ActivityCamaraInfoBinding>() {
    private var mDesc = ""

    override fun ActivityCamaraInfoBinding.initBinding() {
        checkCamera()
    }

    private fun checkCamera(){
        val cameraList = ArrayList<CameraInfo>()
        val cameraCount = Camera.getNumberOfCameras()
        mDesc = "${mDesc}摄像头个数=${cameraCount}"
        for (i in 0 until cameraCount){
            val camera = Camera.open(i)
            val params = camera.parameters
            val cameraInfo = CameraInfo(
                if (i == 0) "前置" else "后置",
                params.flashMode,
                params.focusMode,
                params.sceneMode,
                params.colorEffect,
                params.whiteBalance,
                params.maxZoom,
                params.zoom,
                params.supportedPreviewSizes
            )
            camera.release()
            cameraList.add(cameraInfo)
        }
        val adapter = CameraAdapter(this,cameraList)
        //LayoutManager用于指定RecyclerView的布局方式，
        // 这里使用的LinearLayoutManager是线性布局的意思
        val linearLayoutManager = LinearLayoutManager(this)
        mBinding.rvCamera.layoutManager = linearLayoutManager
        mBinding.rvCamera.adapter = adapter
    }
}